package com.yzz.hzraisedust.hzraseidust.main.pmdetail;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yzz.hzraisedust.hzraseidust.R;
import com.yzz.hzraisedust.hzraseidust.modelbean.PmDetailItemBean;

import java.util.List;

/**
 * Created by zhengzhen on 2017/8/21.
 */

public class PMDetailAdapter  extends BaseAdapter{
    private List<PmDetailItemBean> mItems;
    private Context mContext;
    public PMDetailAdapter(Context context,List<PmDetailItemBean> items){
        mContext = context;
        mItems = items;
    }
    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public Object getItem(int i) {
        return mItems.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder  = null;
        if(view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.pmdetail_list_item_name_layout,null,false);
            holder = new ViewHolder();
            holder.pmUpdateTimeTextView = view.findViewById(R.id.pm_time_textview);
            holder.pmValueTextView = view.findViewById(R.id.pm_value_textview);
            holder.pmNoiseTextView = view.findViewById(R.id.pm_noise_textview);

            view.setTag(holder);
        }
        if(holder == null){
            holder = (ViewHolder) view.getTag();
        }
        PmDetailItemBean item =  mItems.get(i);
        if(item.getPmDescribe() == null) item.concute();
        holder.pmUpdateTimeTextView.setText(item.getUpdatetime());
        holder.pmValueTextView.setTextColor(item.getBackgroudColor());
        holder.pmValueTextView.setText(""+item.getPm10());
       // holder.pmNoiseTextView.setTextColor(item.getNoiseBakcgroudColor());
        holder.pmNoiseTextView.setText(""+item.getPm2_5());

        return view;
    }

    class ViewHolder{
        private TextView pmUpdateTimeTextView;
        private TextView pmValueTextView;
        private TextView pmNoiseTextView;
    }
}
